﻿using System.IO;

namespace GiveAQuiz.Web.Helpers
{
  /// <summary>
  /// Extension methods for classes dealing with IO.
  /// </summary>
  public static class IOExtensions
  {
    /// <summary>
    /// Extension method for the FileInfo object that retrieves the entire
    /// contents of a file and returns the value as a string.
    /// </summary>
    /// <param name="fileInfo">The FileInfo class.</param>
    /// <returns>The contents of the file.</returns>
    public static string GetContents(this FileInfo fileInfo)
    {
      string contents;
      // pull out the contents
      using (var fileStream = new FileStream(fileInfo.FullName, FileMode.Open))
      {
        using (var reader = new StreamReader(fileStream))
        {
          contents = reader.ReadToEnd();
        }
      }
      return contents;
    }
  }
}